/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.JButton;
import model.Contact;

/**
 * Form to edit a contact
 * @author Gautier
 */
public class FormEdit extends FormAdd{

    /**
     * 
     */
    protected JButton cancel;
    private Contact ca;
    
    /**
     * Constructor
     * @param ali arraylist of contact
     * @param c contact object
     */
    public FormEdit(ArrayList ali, Contact c){
        super(ali);
        ca=c;
        
        this.button.setText("Save");
        cancel=new JButton("Cancel");
        cancel.addActionListener(this);
        
        this.t_name.setText(c.getName());
        this.t_firstName.setText(c.getFirstName());
        this.t_address.setText(c.getHomeAddress());
        this.t_pPhone.setText(c.getPersonalPhone());
        this.t_proPhone.setText(c.getProfessionalPhone());
        this.t_email.setText(c.getEmail());
        this.t_home.setText(c.getHomePage());
        this.t_other.setText(c.getOther());
        
        this.cont.add(cancel);
        this.cont.repaint();
        this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==cancel) this.dispose();
        if(e.getSource()==button) {
            ca.editContact(t_name.getText(), t_firstName.getText(), t_address.getText(), t_pPhone.getText(), t_proPhone.getText(), t_email.getText(), t_home.getText(), t_other.getText());
            this.dispose();
        }
    }
    
    
    
}
